﻿using System;
using System.Collections.Generic;
using Giant.Core.Plugins;
using Giant.Services.Cms;
using Giant.Services.Configuration;
using System.Web.Routing;

namespace Giant.Plugin.Widgets.BaiduAnalytics
{
    public class BaiduAnalyticsPlugin : BasePlugin, IWidgetPlugin
    {
        private readonly ISettingService _settingService;
        private readonly BaiduAnalyticsSettings _baiduAnalyticSettings;

        public BaiduAnalyticsPlugin(ISettingService settingService, BaiduAnalyticsSettings baiduAnalyticSettings)
        {
            this._settingService = settingService;
            this._baiduAnalyticSettings = baiduAnalyticSettings;
        }

        public void GetConfigurationRoute(out string actionName, out string controllerName, out System.Web.Routing.RouteValueDictionary routeValues)
        {
            actionName = "Configure";
            controllerName = "WidgetBaiduAnalytics";
            routeValues = new RouteValueDictionary { { "Namespaces", "Giant.Plugin.Widgets.BaiduAnalytics.Controllers" }, { "area", null } };
        }

        public void GetDisplayWidgetRoute(string widgetZone, out string actionName, out string controllerName, out System.Web.Routing.RouteValueDictionary routeValues)
        {
            actionName = "PublicInfo";
            controllerName = "WidgetBaiduAnalytics";
            routeValues = new RouteValueDictionary
            {
                {"Namespaces", "Giant.Plugin.Widgets.WidgetBaiduAnalytics.Controllers"},
                {"area", null},
                {"widgetZone", widgetZone}
            };
        }

        public IList<string> GetWidgetZones()
        {
            return !string.IsNullOrWhiteSpace(_baiduAnalyticSettings.WidgetZone)
                       ? new List<string>() { _baiduAnalyticSettings.WidgetZone }
                       : new List<string>() { "head_html_tag" };
        }
    }
}
